(function($){
	$(function(){
		/************************************top关闭按钮*********************************************/
		$('.topClose').click(function(){
			$('.top_wrap').slideUp(500);
		});
		/*************************************/
		var userName=getCookie('username');
		if(userName!=''){
			$('#login').html('欢迎您！ '+userName+' <a href="javascript:;"> [ 退出  ] </a>');
			$('#login a').click(function(){
				$('#login').html('嘿，欢迎来顺丰优选！<a href="html/login.html">请登录 </a><a href="html/reg.html"> 免费注册</a>')
			})
		}
		/************登录*************/
		var userName=getCookie('username');
		if(userName!=''){
			$('#login').html('欢迎您！ '+userName+' <a href="javascript:;"> [ 退出  ] </a>');
			$('#login a').click(function(){
				$('#login').html('嘿，欢迎来顺丰优选！<a href="html/login.html">请登录 </a><a href="html/reg.html"> 免费注册</a>')
			});
		}
		/************************************轮播图*********************************************/
		var count=0;
		var lunboLeft=$('.lunbo').css('left');
		var iIndex=0;
		var arrBgColor=["rgb(111, 179, 138)","rgb(244, 234, 224)","rgb(249, 246, 241)","rgb(34, 22, 19)","rgb(166, 230, 242)","rgb(192, 191, 41)","rgb(192, 191, 41)","rgb(241, 208, 113)"];
		$('.lunbo_btn a').removeClass('hover').eq(iIndex).addClass('hover');
		$('.banner_wrap').css('background',arrBgColor[iIndex]);
		var timer=setInterval(move,1000);
		function move(){
			clearInterval(timer);
			count+=1000;
			$('.lunbo').stop(true).delay(500).animate({left:-count},500,function(){
				if(iIndex>=7){
					iIndex=-1;
				}
				$('.lunbo_btn a').removeClass('hover').eq(++iIndex).addClass('hover');
				$('.banner_wrap').css('background',arrBgColor[iIndex]);
				clear();
			});
		}
		function clear(){
			timer=setInterval(move,3000);
			if(count>=8000){
				count=0;
				$('.lunbo').css('left','0');
			}
		}
		$('.banner_wrap').mouseenter(function(){
			clearInterval(timer);
			$('.lunbo').stop(true);
		}).mouseleave(function(){
			move();
		});
		/************************************轮播按钮*********************************************/
		$('.lunbo_btn a').each(function(i){
			$('.lunbo_btn a').eq(i).mouseenter(function(){
				clearInterval(timer);
				$('.lunbo').stop(true);
				$('.lunbo_btn a').removeClass('hover').eq(i).addClass('hover');
				$('.banner_wrap').css('background',arrBgColor[i]);
				count=i*1000;
				$('.lunbo').stop(true).animate({
					left:-count
				},300);
			}).mouseleave(function(){
				iIndex=i;
				move();
			});
		});
		/************************************banner右边样式*********************************************/
		$('.banner_right').mouseout(function(){
			$('.banner_right a').removeClass('hover');
		});
		$('.banner_right a').each(function(i){
			$(this).mouseover(function(){
				$('.banner_right a').addClass('hover').eq(i).removeClass('hover');
			});
		});
		/************************************hot左边*********************************************/
		$('.hot_li').each(function(i){
			$(this).mouseenter(function(){
				$('.gBtn').eq(i).animate({
					bottom:15,
				});
			}).mouseleave(function(){
				$('.gBtn').stop(true,true).eq(i).animate({
					bottom:-24,
				});
			})
		})
		/************************************限时抢购-下期预告*********************************************/
		$('.time_buy_left02').css('display','none');
		$('.time_buy_left01').css('display','block');
		$('.tright a').click(function(){
			$('.time_buy_left01').css('display','none');
			$('.time_buy_left02').css('display','block');
		})
		$('.tright1 a').click(function(){
			$('.time_buy_left02').css('display','none');
			$('.time_buy_left01').css('display','block');
		});
		
		
		/**************定时器*************/
		var miao=12*60*60*1000;
		var timer_jishi=setInterval(function(){
			miao-=1000;
			iHour = parseInt(miao/60/60/1000)%24;
			iMinute = parseInt(miao/60/1000)%60;
			iSecond = parseInt(miao/1000)%60;
			iHour = iHour<10 ? "0" + iHour:"" + iHour;
			iMinute = iMinute<10 ? "0"+iMinute:"" + iMinute;
			iSecond = iSecond<10 ? "0"+iSecond:"" + iSecond;
		 	$(".nowHour1").html(iHour[0]);
			$(".nowHour2").html(iHour[1]);
			$(".nowMin1").html(iMinute[0]);
			$(".nowMin2").html(iMinute[1]);
			$(".nowSencond1").html(iSecond[0]);
			$(".nowSencond2").html(iSecond[1]);
		},1000);
		
		/************************************楼层初始化样式*********************************************/
		/******颜色*******/
		var arrColor=['#76AC25','#fa648c','#ff6c00','#fa648c','#d12e49','#f08c18','#78b270'];
		$('.main_right').each(function(i){
			$(this).css('border-color',arrColor[i]);
			$('.main_menu_top').eq(i).css('background',arrColor[i]);
		});
		/*******左侧导航鼠标划过样式*******/
		$('.main_menu_top').each(function(i){
			$('.main_menu_top').eq(i).mouseover(function(){
				$('.main_menu_top').removeClass('hover').eq(i).addClass('hover');
			}).mouseout(function(){
				$('.main_menu_top').removeClass('hover');
			})
		})
		/******right_left样式*****/
		$('.main dl dt').each(function(i){
			$(this).mouseover(function(){
				$('.putCar').stop(true,true).eq(i).animate({
					bottom:0
				});
			}).mouseout(function(){
				$('.putCar').stop(true,true).eq(i).animate({
					bottom:-24
				});
			});
		});
		
		/******right_right样式*****/
		$('.rimg').each(function(i){
			$('.rimg').eq(i).mouseenter(function(){
				$('.rimg a').removeClass('hover').eq(i).addClass('hover');
			}).mouseleave(function(){
				$('.rimg a').removeClass('hover');
			});
		});
		/*******************************************相关de特效**********************************************/
		$('.weidao_btn').css('display','none');
		$('.weidao .slide').mouseenter(function(){
			$('.weidao_btn').css('display','block');
		}).mouseleave(function(){
			$('.weidao_btn').css('display','none');
		});
		var ulL=parseInt($('.weidao .slide ul').css('left'));
		var liW=$('.weidao .slide li:first').width();
		slideCon();
		function slideCon(){
			if(ulL<=-liW&&ulL>-2*liW){
				$('.slideControls span').removeClass('cur').eq(1).addClass('cur');
			}else{
				$('.slideControls span').removeClass('cur').eq(0).addClass('cur');
			}
		}
		$('.btn_next').click(function(){
			ulL=parseInt($('.weidao .slide ul').css('left'));
			liW=$('.weidao .slide li:first').width();
			ulL=ulL-liW;
			slideCon();
			$('.weidao .slide ul').stop(true).animate({left:ulL},function(){
				if(Math.abs(ulL)>=2*liW){
					$('.weidao .slide ul').css({left:0});
				}
			});
		});
		$('.btn_prev').click(function(){
			ulL=parseInt($('.weidao .slide ul').css('left'));
			if(Math.abs(ulL)==0){
				$('.weidao .slide ul').css({left:-2*liW});
				ulL=parseInt($('.weidao .slide ul').css('left'));
			}
			ulL=ulL+liW;
			slideCon();
			$('.weidao .slide ul').stop(true).animate({left:ulL});
		});
		$('.slideControls span').each(function(i){
			$(this).click(function(){
				$('.slideControls span').removeClass('cur').eq(i).addClass('cur');
				$('.weidao .slide ul').stop(true).animate({left:-(i*liW)});
				
			})
		})
		/*******************************热门晒单***********************************/
		var t=0;
		var timer01=setInterval(shareMove,3000);
		function shareMove(){
			clearInterval(timer01);
			t+=120;
			$('.share_con').delay(2000).animate({top:-t},1000,clearMove);
		}
		function clearMove(){
			timer01=setInterval(shareMove,3000);
			if(t>=360){
				t=0;
				$('.share_con').css('top',0);
			}
			
		}
		/*******************************发现优品***********************************/
		var disUlL=0;
		$('.dis_cap span').click(function(){
			disUlL+=300;
			if(disUlL>600){
				disUlL=0;
			}
			$('.dis_list ul').css({left:-disUlL});
		});
		$('.dis_list li').each(function(i){
			$(this).mouseover(function(){
				$('.dis_list li .dis_mask').css('display','none').eq(i).css('display','block');
				$('.dis_list li p').css('display','none').eq(i).css('display','block');
			}).mouseout(function(){
				$('.dis_list li .dis_mask').css('display','none');
				$('.dis_list li p').css('display','none');
			})
		})
		
		/**************选择城市**************/
		var 
			divSheng=$('.dis_city ul .add_sheng div'),
			divShi=$('.dis_city ul .add_shi div ');
		$('.dis_address').mouseenter(function(){
			$('.dis_city').addClass('hover');
			divShi.css('display','none');
			divSheng.css('display','block');
			$('.add_sheng').css({
				borderBottom:0,
			});
		}).mouseleave(function(){
			$('.dis_city').removeClass('hover');
		});
		
		$('.li_close').click(function(){
			$('.dis_city').removeClass('hover');
		});
		$('.dis_city li').each(function(i){
			if(i<2){
				$('.dis_city li').eq(i).click(function(){
					$('.dis_city li').css('border-bottom','2px solid #e8e8e8').eq(3).css('border-bottom','0');
					$(this).css('border-bottom','0');
					$('.dis_city li div').css('display','none').eq(i).css('display','block');
				})
			}else{
				return false;
			}
		});
		var shengName=$('.add_sheng div p a');
		var shiName=$('.add_shi div p a');
		shengName.each(function(i){
			$(this).click(function(){
				var text=$('.add_sheng div p a').eq(i).html();
				$('.dis_address span').eq(0).html(text);
				$('.add_sheng span').html(text);
				
			});
		})
		shiName.each(function(i){
			$(this).click(function(){
				var text=$('.add_shi div p a').eq(i).html();
				$('.add_shi span').html(text);
			});
		});
		/***********购物车链接************/
		$('.slide_shop').click(function(){
			var newWin=window.open('html/car.html');
		});
		/****************加入购物车*****************/
		$('.gBtn a').each(function(i){
			$(this).click(function(){
				var goodMess=getCookie('mess');
				if(goodMess==''||goodMess==null){
					var obj=new Object();
					obj.id=i;
					obj.name=escape($('.hot_li').eq(i).children('a').attr('title'));
					obj.src=$('.lazy').eq(i).attr('src');
					obj.price=$('.hot_li').eq(i).children('.price').children('i').text();
					obj.num=1;
					var arr=[obj];
					document.cookie="mess="+JSON.stringify(arr)+";path=/";
				}else{
					var arr=JSON.parse(goodMess);
					var obj=new Object();
					var bFlag=true;
					obj.id=i;
					obj.name=escape($('.hot_li').eq(i).children('a').attr('title'));
					obj.src=$('.lazy').eq(i).attr('src');
					obj.price=$('.hot_li').eq(i).children('.price').children('i').text();
					obj.num=1;
					for(var j=0;j<arr.length;j++){
						if(arr[j].id==i){
							bFlag=false;
							arr[j].num++;
						}
					}
					if(bFlag){
						arr.push(obj);
					}
				}
				$('.hover02').text(arr.length);
				document.cookie="mess="+JSON.stringify(arr)+";path=/";
			});
		});
		/**********购物车数量**********/
		var goodMess=getCookie('mess');
		if(goodMess==''||goodMess==null){
			$('.hover02').text(0);
			
		}else{
			var arr=JSON.parse(goodMess);
			$('.hover02').text(arr.length);
			if($('.hover02').text()!='0'){
				$('.shop_car').click(function(){
					window.open('html/car.html');
				});
			}
		}
		$('.slide_common').eq(0).mouseover(function(){
			var goodMess=getCookie('mess');
			if(goodMess==''||goodMess==null){
				$(this).children('.shop_car_list').css('display','block');
			}else{
				$(this).children('.shop_car_list').css('display','none');
			}
		});
		$('.slide_common').eq(0).click(function(){
			var goodMess=getCookie('mess');
			if(goodMess==''||goodMess==null){
				$(this).children('.shop_car_list').css('display','block');
			}else{
				window.open('html/car.html');
			}
		});
		function getCookie(name){
			var str=document.cookie;
			var arr=str.split("; ");
			for(var i=0;i<arr.length;i++){
				var address=arr[i].indexOf("=");
				var name1=arr[i].slice(0,address);
				var value=arr[i].slice(address+1,arr[i].length);
				if(name==name1){
					return value;
				}
			}
			return "";
		}	
	});
})(jQuery);





